package com.example.nextstream.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.nextstream.mapper.PropertiesMapper;
import com.example.nextstream.models.Properties;
import com.example.nextstream.service.PropertiesService;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.stereotype.Service;

import java.util.List;


@Service("PropertiesService")
public class PropertiesServiceImpl extends ServiceImpl<PropertiesMapper, Properties> implements PropertiesService {
    @Override
    public String getPropertiesById(String name) {
        return baseMapper.selectById(name).getValue();
    }

    @Override
    public Boolean deletePropertiesById() {
        return null;
    }

    @Override
    public Boolean updateProperties(Properties properties) {
        try {
            if (baseMapper.updateById(properties) == 0) {
                this.createProperties(properties);
            }
        } catch (DataIntegrityViolationException e) {
            return false;
        }
        return true;
    }

    @Override
    public Page<Properties> listProperties() {
        return null;
    }

    @Override
    public Boolean createProperties(Properties properties) {
        baseMapper.insert(properties);
        return true;
    }
    @Override
    public List<Properties> getProperties() {
        return baseMapper.selectList(null);
    }
}
